package javaproject;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
import javax.vecmath.Color3f;

public class Config{
    //------------------CONFIGURATION------------------//
    //誰在畫面內?
    //boolean showWall = false;
    //boolean showBullet = false;
    //boolean showCapsule = false;
    static boolean showWall = false;
    static boolean showBullet = true;
    static boolean showCapsule = true;

    //全場
    static int refreshRate = 10;                                         //反應時間(ms)
    static boolean AA = false;                                                 //全域反鋸齒
    static boolean FPS = false;                                                //開啟FPS測試
    static boolean debug = false;
    //static boolean debug = true;
    static double outOfScreen = 20;						//丟到這麼遠可以算畫面外

    //場景大小
    static int width = 900;
    static int height = 750;

    static int edgeLength = 8;                                           //必須為偶數
    static int multiplier = 5;                                           //必須為奇數
    static int w = ((edgeLength+1)*multiplier)-1;
    static int h = ((edgeLength+1)*multiplier)-1;
//                      d = ((edgeLength+1)*multiplier)-1;                        //舞台長寬高
//    static int  d = (edgeLength+1)*multiplier/12;
    static int  d = -1;
    static float blockSize = 0.004f;
    static float blockW = blockSize*multiplier,
	  blockH = blockSize*multiplier,
	  blockD = blockSize*multiplier;                                //方塊長寬深
    
    static float boundingW = Config.blockW*(Config.w+1);            //bounding Box的半邊長
    static float boundingH = Config.blockH*(Config.h+1);
    static float boundingD = Config.blockD*(Config.d+1);
    
    static float moveFactor = 5f;
    static float moveX = blockW/moveFactor,							//Vic_Viper每週期移動長度，越小移動越細緻
	  moveY = blockH/moveFactor,
	  moveZ = blockD/moveFactor;

    //子彈
    static int maxBullets = 5000;                                            //場上最大子彈數
    static int initBullets = 50;                                              //起始數
    static float bulletSize = 0.01f;
    static double radius = 2.1;                                             //子彈發射球表面離原點半徑
    static double hitRadius = 0.04;                                           //Vic_Viper判定範圍
    static Color3f bulletColor = new Color3f(0.6f,0.6f,0.6f);
    //static double forwardStep=0.003;					   //子彈前進速度
    static double forwardStep=moveX;					   //子彈前進速度
    static double offsetFactor=1;				      //偏差範圍
    static double offsetRange=forwardStep*offsetFactor;				      //偏差範圍
    static double mutateFactor=0.2;				      //子彈變成特殊子彈的機率
    static double explodeDistance=Config.boundingW*2/3;				      //開始爆炸的範圍(離中心)

    //Capsule
    static int initCapsules = 2;
    static int maxCapsules = 5;
    static int emergeTime = 1000;							//每幾毫秒亂數加入Capsule
    static double emergeRate = 0.5;							//加入機會
    static double disappearRate = 0.5;							//跑完一輪消失的機會
    static double capsuleRadius = 0.05;

    //Vic_Viper & Options
    static float optionSize = 0.010f;
    static Color3f optionColor = new Color3f(1,1,0);
    static float vic_viperSize = 0.06f;
    static float threshold = 0.93f;                                            //調整option空隙的臨界值
    static float gap = bulletSize/1.6f;                            //vic_viper和option之間的距離
    //長度
    static int initLength = 4;                                         //初始蛇長
    static int maxLength = 10;                                          //最大蛇長

    //爆炸衝擊波
    static double extendStep = 0.02;							//爆炸時衝擊波的擴散速度
    static double areaFactor = 0.5;							//爆炸範圍中心半徑為衝擊波的?倍


    static float lineWidth = 1.2f;                                       //所有線粗

    //Wiimote
    static int lockTime = 500;                                             //wiimote動作的間隔時間
    static double actionThreshold = 0.6;                                      //加速度起始條件
    static double rotateThreshold = 10;                                          //轉轉起始條件(度)
    static double rotateFactor = 90;                                          //轉轉增加量
    static double rotateStep = Math.PI/rotateFactor;                                          //轉轉增加量
    static double continuousRotateFactor = 1440;
    static double continuousRotateStep = Math.PI/continuousRotateFactor;                                          //轉轉增加量

    //旋轉
    static int rotateRefreshRate = 20;						    //轉動更新速度
    static double rotatePeriodFactor = 50;
    static double rotatePeriod = rotatePeriodFactor*rotateRefreshRate;						    //大轉動幾毫秒內完成

    //分數
    static float scoreX = -28;								//分數字體位置
    static float scoreY = 21.5f;
    static float scoreZ = 0;
    static float timeX = -28;								//分數字體位置
    static float timeY = 20f;
    static float timeZ = 0;
    static float lifeX = 26;								//生命數字體位置
    static float lifeY = 21.5f;
    static float lifeZ = 0;
    static float lifeIconX = 24;								//小飛機圖示(生命)位置
    static float lifeIconY = 22.5f;
    static float lifeIconZ = 0;
    static double timeBonus = 0.003;                                             //時間漸增額外加分
    static double optionBonus = 0.1;                                             //option額外加分
    static int difficultyLevel = 1000;						    //難易度門檻

    //顯示agent
    static float agentCapsuleX = -25;
    static float agentCapsuleY = -17.6f;
    static float agentCapsuleZ = 0;
    static float agentCentralX = -25;
    static float agentCentralY = -18.7f;
    static float agentCentralZ = 0;
    static float agentWallX = -25;
    static float agentWallY = -19.8f;
    static float agentWallZ = 0;
    static float agentCloseX = -25;
    static float agentCloseY = -20.9f;
    static float agentCloseZ = 0;
    static float agentBlankX = -25;
    static float agentBlankY = -22f;
    static float agentBlankZ = 0;
    static float starX = -26.5f;
    static float starY = -16.6f;
    static float starZ = 0;
    
    //牆壁
    static double initSpeed = 0.002;                                     //牆壁移動速度
    static double wallSpeedStep = 0.05;
    static Color3f wallColor = new Color3f(0.3f, 0.3f, 0.3f);

    //外框
    static Color3f frameColor = new Color3f(0.9f,0.9f,0.9f);
    static float frameTrans = 0.5f;

    //導引線
    static Color3f guideLineColor = new Color3f(1,0,0);
    //校準
    static double scale = 0.8;
    static double rotX = Math.PI*-65/360;                                      //X旋轉初始值
    static double rotZ = Math.PI*-10/360;                                       //Z旋轉初始值
    static double posOffsetX = 0.00;
    static double posOffsetY = 0.1;
    static double posOffsetZ = 0.00;                   //修正位置，讓整個方塊至於畫面中心

    Config()
    {
	Scanner configFile;
	try {
	    configFile = new Scanner(new FileInputStream("config.txt"));
	    while(configFile.hasNext())
	    {
		String input = configFile.nextLine();
		if(!input.startsWith("//") && !input.isEmpty())	//忽略只有一行的註解
		{
		    String[] str;
		    str = input.split("//");
		    str = str[0].split("=");
		    String name = str[0];
		    String value = str[1];
		    if(value.indexOf(' ') != -1)
			value = value.substring(0, value.indexOf(' '));
		    if(value.indexOf('\t') != -1)
			value = value.substring(0, value.indexOf('\t'));
		    //顯示
		    if(name.equals("showWall"))
			showWall = Boolean.valueOf(value);
		    else if(name.equals("showBullet"))
			showBullet = Boolean.valueOf(value);
		    else if(name.equals("showCapsule"))
			showCapsule = Boolean.valueOf(value);

		    //全場
		    else if(name.equals("refreshRate"))
			refreshRate = Integer.valueOf(value);
		    else if(name.equals("AA"))
			AA = Boolean.valueOf(value);
		    else if(name.equals("FPS"))
			FPS = Boolean.valueOf(value);
		    else if(name.equals("debug"))
			debug = Boolean.valueOf(value);
		    else if(name.equals("outOfScreen"))
			outOfScreen = Double.valueOf(value);

		    //場景
		    else if(name.equals("width"))
			width = Integer.valueOf(value);
		    else if(name.equals("height"))
			height = Integer.valueOf(value);
		    else if(name.equals("edgeLength"))
			edgeLength = Integer.valueOf(value);
		    else if(name.equals("multiplier"))
			multiplier = Integer.valueOf(value);
		    else if(name.equals("blockSize"))
			blockSize = Float.valueOf(value);
		    else if(name.equals("moveFactor"))
			moveFactor = Float.valueOf(value);

		    //子彈
		    else if(name.equals("maxBullets"))
			maxBullets = Integer.valueOf(value);
		    else if(name.equals("initBullets"))
			initBullets = Integer.valueOf(value);
		    else if(name.equals("bulletSize"))
			bulletSize = Float.valueOf(value);
		    else if(name.equals("radius"))
			radius = Double.valueOf(value);
		    else if(name.equals("hitRadius"))
			hitRadius = Double.valueOf(value);
		    else if(name.equals("bulletColor"))
		    {
			String color[] = value.split(",");
			bulletColor = new Color3f(Float.valueOf(color[0]), Float.valueOf(color[1]), Float.valueOf(color[2]));
		    }
		    else if(name.equals("forwardStep"))
			forwardStep = Double.valueOf(value);
		    else if(name.equals("offsetFactor"))
			offsetFactor = Double.valueOf(value);

		    //Capsule
		    else if(name.equals("initCapsules"))
			initCapsules = Integer.valueOf(value);
		    else if(name.equals("maxCapsules"))
			maxCapsules = Integer.valueOf(value);
		    else if(name.equals("emergeTime"))
			emergeTime = Integer.valueOf(value);
		    else if(name.equals("emergeRate"))
			emergeRate = Double.valueOf(value);
		    else if(name.equals("disappearRate"))
			disappearRate = Double.valueOf(value);
		    else if(name.equals("capsuleRadius"))
			capsuleRadius = Double.valueOf(value);

		    //Vic_Viper & Options
		    else if(name.equals("optionSize"))
			optionSize = Float.valueOf(value);
		    else if(name.equals("optionColor"))
		    {
			String color[] = value.split(",");
			optionColor = new Color3f(Float.valueOf(color[0]), Float.valueOf(color[1]), Float.valueOf(color[2]));
		    }
		    else if(name.equals("vic_viperSize"))
			vic_viperSize = Float.valueOf(value);
		    else if(name.equals("threshold"))
			threshold = Float.valueOf(value);

		    //蛇長
		    else if(name.equals("initLength"))
			initLength = Integer.valueOf(value);
		    else if(name.equals("maxLength"))
			maxLength = Integer.valueOf(value);

		    //爆炸衝擊波
		    else if(name.equals("extendStep"))
			extendStep = Double.valueOf(value);
		    else if(name.equals("areaFactor"))
			areaFactor = Double.valueOf(value);

		    //外觀
		    else if(name.equals("lineWidth"))
			lineWidth = Float.valueOf(value);

		    //Wiimote
		    else if(name.equals("lockTime"))
			lockTime = Integer.valueOf(value);
		    else if(name.equals("actionThreshold"))
			actionThreshold = Float.valueOf(value);
		    else if(name.equals("rotateThreshold"))
			rotateThreshold = Integer.valueOf(value);
		    else if(name.equals("rotateFactor"))
			rotateFactor = Integer.valueOf(value);

		    //分數
		    else if(name.equals("scoreX"))
			scoreX = Float.valueOf(value);
		    else if(name.equals("scoreY"))
			scoreY = Float.valueOf(value);
		    else if(name.equals("scoreZ"))
			scoreZ = Float.valueOf(value);
		    else if(name.equals("timeBonus"))
			timeBonus = Double.valueOf(value);
		    else if(name.equals("optionBonus"))
			optionBonus = Double.valueOf(value);
		    else if(name.equals("difficultyLevel"))
			difficultyLevel = Integer.valueOf(value);

		    //牆壁
		    else if(name.equals("initSpeed"))
			initSpeed = Double.valueOf(value);
		    else if(name.equals("wallColor"))
		    {
			String color[] = value.split(",");
			wallColor = new Color3f(Float.valueOf(color[0]), Float.valueOf(color[1]), Float.valueOf(color[2]));
		    }

		    //外框
		    else if(name.equals("frameColor"))
		    {
			String color[] = value.split(",");
			frameColor = new Color3f(Float.valueOf(color[0]), Float.valueOf(color[1]), Float.valueOf(color[2]));
		    }
		    else if(name.equals("frameTrans"))
			frameTrans = Float.valueOf(value);

		    //校準
		    else if(name.equals("posOffsetX"))
			posOffsetX = Float.valueOf(value);
		    else if(name.equals("posOffsetY"))
			posOffsetY = Float.valueOf(value);
		    else if(name.equals("posOffsetZ"))
			posOffsetZ = Float.valueOf(value);
		}
	    }
	} catch (FileNotFoundException ex) {
	    System.out.println("找不到設定檔，使用預設設定");
	}
    }
}
